<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category ArticleController.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/7/14  17:26
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Index;


use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\Category;
use App\Services\ArticleService;
use App\Services\CategoryService;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
    public function index(Request $request)
    {
        $req['perPage'] = 8;
        $hots = ArticleService::getInstance()->getList($req);
        $hots = $hots['data'];

        $req['perPage'] = 3;
        $req['top'] = 1;
        $tops = ArticleService::getInstance()->getList($req);
        $tops = $tops['data'];

        $category = CategoryService::getInstance()->getCateLevel([]);

        $compact = compact('hots', 'tops', 'request', 'category');
        return view('index.article.index',$compact);
    }

    public function show(Request $request)
    {
        $list = ArticleService::getInstance()->getList($request);
        $list = $list['data'];
        $compact = compact('list');

        $html = view('index.article._section',$compact)->render();
        $data['html'] = $html;
        $data['last_page'] = $list['last_page'];
        return response()->json(['code'=>1 ,'data'=>$data]);
    }

    public function place_index(Request $request)
    {
        $compact = compact('request');
        return view('index.article.place_index',$compact);
    }

    public function place_show(Request $request)
    {
        $list = ArticleService::getInstance()->getList($request);
        $list = $list['data'];
        $compact = compact('list');

        $html = view('index.article._place_section',$compact)->render();
        $data['html'] = $html;
        $data['last_page'] = $list['last_page'];
        return response()->json(['code'=>1 ,'data'=>$data]);
    }

    public function read(Request $request)
    {
        $article = ArticleService::getInstance()->getRead($request->id);
        $compact = compact('article');
        return view('index.article.read',$compact);

    }

    public function search(Request $request)
    {
        $req['perPage'] = 8;
        $hots = ArticleService::getInstance()->getList($req);
        $req['perPage'] = 3;
        $req['top'] = 1;
        $tops = ArticleService::getInstance()->getList($req);

        $compact = compact('hots', 'tops', 'request');
        return view('index.article.index',$compact);
    }

}
